import { http } from '@/utils/http'

const AUTH_BASE_URL = '/core/prodReport'
const qualityApi = {
  getProdReport(params: QualityQueryParams) {
    const query = encodeURIComponent(JSON.stringify({ ...params }))
    return http<QualityData>({
      url: `${AUTH_BASE_URL}/getProdReportList?object=${query}`,
      method: 'GET',
    })
  },

  saveOrUpdateProdReport(params: QualityData) {
    return http<QualityData>({
      url: `${AUTH_BASE_URL}/saveOrUpdateProdReport`,
      method: 'POST',
      data: params,
    })
  },
}

export default qualityApi

// {"pageNum":1,"pageSize":10,"qualityType":1,"status":0,"code":"12","parentCode":"12","productType":"PRO0000044","productName":"12","reportName":"12","timeScopes":["2025-02-27","2025-03-01"]}

export interface QualityQueryParams extends QueryParams {
  qualityType: number
  status: number
  code?: string
  parentCode?: string
  productType?: string
  productName?: string
  reportName?: string
  timeScopes?: string[]
}
/**
 * 质检记录

 */
export interface QualityData {
  actualQuantity: number // 实际数量

  code: string // 质检单号

  id: number // 记录ID

  orderType: number // 订单类型, 0=生产单号, 1=采购单号

  parentCode: string // 生产单号

  physicalImage: string[] // 物理图片列表

  productCategory: string // 产品分类

  productCode: string // 产品代码

  productName: string // 产品名称

  purchaseQuantity: number // 采购数量

  qualifiedQuantity: number // 合格数量

  unit: string // 单位

  qualifiedRate: number // 合格率

  qualityType: number // 质检类型 0=产品质检单, 1=原材料质检单

  reportImage: string[] // 报告图片

  reportName: string // 报告名称

  status: number // 状态 0:待检验 1:检验中 2:检验通过 3:检验不通过

  supplierCode: string // 供应商代码

  supplierName: string // 供应商名称

  timeScopes?: string[] // 时间范围
}
